FROM python:3.11-slim

ENV PYTHONDONTWRITEBYTECODE=1 \
    PYTHONUNBUFFERED=1

WORKDIR /app

# 安装 mysqlclient 依赖、等待脚本依赖
RUN apt-get update && apt-get install -y --no-install-recommends \
    build-essential default-libmysqlclient-dev pkg-config netcat-openbsd \
    && rm -rf /var/lib/apt/lists/*

COPY requirements.txt /app/
RUN pip install --no-cache-dir -r requirements.txt

COPY . /app

COPY entrypoint.sh /entrypoint.sh
RUN chmod +x /entrypoint.sh
RUN sed -i 's/\r$//' /entrypoint.sh
RUN touch .env

# 统一静态与媒体目录，便于与 Nginx 共享
ENV STATIC_ROOT=/vol/static \
    MEDIA_ROOT=/vol/media

EXPOSE 8000

CMD ["/entrypoint.sh"]